
//index.js
//获取应用实例
const app = getApp()
 
Page({
  data: {
    old: '',
    new: '',
    once: '',
  },
  
  onShow: function () {
    // 生命周期函数--监听页面显示
    wx.hideTabBar({})
  },
  onLoad: function () {
    wx.setNavigationBarTitle({ title: '修改密码' })
  },
 
 
  // 获取输入账号 
  passwordOldInput: function (e) {
    this.setData({
      old: e.detail.value
    })
  },
 
  // 获取输入密码 
  passwordNewInput: function (e) {
    this.setData({
      new: e.detail.value
    })
  },
  passwordNewOnceInput: function (e) {
    this.setData({
      once: e.detail.value
    })
  },
  
  // 注册处理
  login: function () {
    var that = this;
    var uid = wx.getStorageSync('uid');
    var pwd = wx.getStorageSync('pwd');
    if (this.data.old.length == 0 || this.data.new.length == 0||this.data.once.length == 0) {
      wx.showToast({
        title: '密码不能为空',
        icon: 'none',
        duration: 2000
      })
    } else {
      if(this.data.new!=this.data.once){
        wx.showToast({
          title: '两次密码不一致',
          icon: 'none',
          duration: 2000
        })
        return
      }
      if(this.data.old!=pwd){
        wx.showToast({
          title: '原密码不正确',
          icon: 'none',
          duration: 2000
        })
        return
      }
      wx.request({
        url: app.globalData.baseUrl +'/user/upPwd', // 仅为示例，并非真实的接口地址
        method: 'post',
        data: {
          id: uid,
          pwd: that.data.new,
       
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        success(res) {
          if (res.data.code == 0) {
           
            
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 2000
            })
            wx.navigateBack(-1)
          } 
        }
      })
    }
  }
})
